package com.hqbzl.c1;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

@Slf4j
public class TestPark {
    public static void sleep(long t) {
        try {
            TimeUnit.SECONDS.sleep(t);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        final Thread thread = new Thread(() -> {
            log.debug("start...");
            sleep(1);
            log.debug("park");
            LockSupport.park();
            log.debug("resume...");
        }, "t1");
        thread.start();

        sleep(2);
        log.debug("unpark");
        LockSupport.unpark(thread);
    }

    public static void main1(String[] args) {
        final Thread thread = new Thread(() -> {
            log.debug("start...");
            sleep(2);
            log.debug("park");
            LockSupport.park();
            log.debug("resume...");
        }, "t1");
        thread.start();
        sleep(1);
        log.debug("unpark");
        LockSupport.unpark(thread);
    }
}
